
extern crate rand;
use rand::Rng;

extern crate simple_parallel;
extern crate crossbeam;

mod common;
mod simvec_io;

use common::init;
use common::get_mean;

use simvec_io::get_instances;
use simvec_io::save_parameters;


// impl Repr {
//     fn set(&mut self, i:usize, v:f64) {
//         self.v[i] = v;
//     }
// }

// MatrixFactorization: Regression
mod simvec_s;
use simvec_s::run;

mod simvec_m;

fn main() {
    println!("x");

    let location = "data.txt";

    let mut data = get_instances(location);

    let mean = get_mean(&data);
    println!("{:.4}",mean);

    let n = 25;

    let (mut uu,mut vv) = init(n, &data);

    println!("{},{}",uu.len(),vv.len());

    let cnt = 1000;
    let mut rng = rand::thread_rng();
    rng.shuffle(&mut data);
    
    for z in 0..cnt {
        //let err = run(n,&data,&mut uu,&mut vv);
        let err = simvec_m::run(n,&data, &mut uu, &mut vv);
        // let err = res.0;
        // uu = res.1;
        // vv = res.2;
        println!("{},{:.4}",z,err);
    }

    save_parameters(&uu,"model.u.txt");
    save_parameters(&vv,"model.v.txt");

}
